package com.kitty.game.equip.service;

import com.kitty.game.role.model.Role;
import com.kitty.game.equip.service.EquipService;
import com.kitty.game.equip.EquipDataPool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;

@Service
public class SuitService {
    @Autowired
    EquipService equipService;

    /**
     * 判断套装是否生效 并修改套装ID和发光ID
     */
    public void loadSuit(Role role, List<Short> equipLevels, Set<Integer> suitPolars) {
        boolean isEnableSuit = equipService.isEnableSuit(equipLevels, suitPolars);
        if (isEnableSuit) {
            int polar = suitPolars.iterator().next();
            int suitId = getSuitId(equipLevels.get(0), role.getGender(), role.getPolar());
            role.setSuitId(suitId);
            role.setSuitLightId(7000 + polar);
        } else {
            role.setSuitId(0);
            role.setSuitLightId(0);
        }
    }


    /**
     * 取套装ID
     */
    public int getSuitId(int level, int gender, int polar) {
        List<Integer> polars = Arrays.asList(1, 2, 3, 4, 5);
        List<Integer> levels = Arrays.asList(70, 80, 90, 100, 110, 120, 130 , 140 ,150 , 160 ,170 );
        List<Integer> genders = Arrays.asList(1, 2);
        /**套装等级是整数的 所以需要把等级取整数*/
        level = (int) (Math.floor(level / 10) * 10);
        if (!levels.contains(level) || !genders.contains(gender) || !polars.contains(polar)) {
            /**小于70没有套装*/
            return 0;
        }
        return EquipDataPool.suitDatas.get(level).get(gender).get(polar);
    }

}
